package com.gitee.qdbp.general.trade.api.order.main.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.gitee.qdbp.able.jdbc.paging.PartList;
import com.gitee.qdbp.base.annotation.DataIsolation;
import com.gitee.qdbp.base.annotation.OperateTraces;
import com.gitee.qdbp.base.enums.DataState;
import com.gitee.qdbp.general.trade.enums.OrderState;
import com.gitee.qdbp.general.trade.enums.OrderType;

/**
 * 订单主实体类
 *
 * @author zhh
 * @version 180626
 */
@OperateTraces(id = "id")
@DataIsolation("tenantCode")
public class OrderFormBean implements Serializable {

    /** 版本序列号 **/
    private static final long serialVersionUID = 1L;

    /** 表名 **/
    public static final String TABLE = "vml_order_form";

    /** 主键 **/
    private String id;

    /** 商家租户编号 **/
    private String tenantCode;

    /** 订单类型(0.捐款订单|1.商品订单) **/
    private OrderType orderType;

    /** 关联业务ID **/
    private String dataId;

    /** 订单内容(多个商品取总价最高的那个,加等几件) **/
    private String orderContent;

    /** 用户ID **/
    private String userId;

    /** 总金额=商品金额-折扣+运费 **/
    private Double totalAmount;

    /** 商品金额 **/
    private Double goodsAmount;

    /** 折扣金额 **/
    private Double discountAmount;

    /** 运费金额 **/
    private Double freightAmount;

    /** 已支付金额 **/
    private Double paidAmount;

    /** 商品总件数 **/
    private Integer totalQuantity;

    /** 已发货件数 **/
    private Integer deliverQuantity;

    /** 创建时间 **/
    private Date createTime;

    /** 过期时间 **/
    private Date expireTime;

    /** 订单状态(0.待支付|1.已支付|2.已交付|3.已完成|4.已取消|5.已过期) **/
    private OrderState orderState;

    /** 选项 **/
    private OrderFormOptions options;

    /** 查询关键字 **/
    private String queryKeywords;

    /** 数据状态:0为正常|其他为删除 **/
    private DataState dataState;

    /** 获取主键 **/
    public String getId() {
        return id;
    }

    /** 设置主键 **/
    public void setId(String id) {
        this.id = id;
    }

    /** 获取商家租户编号 **/
    public String getTenantCode() {
        return tenantCode;
    }

    /** 设置商家租户编号 **/
    public void setTenantCode(String tenantCode) {
        this.tenantCode = tenantCode;
    }

    /** 获取订单类型(0.捐款订单|1.商品订单) **/
    public OrderType getOrderType() {
        return orderType;
    }

    /** 设置订单类型(0.捐款订单|1.商品订单) **/
    public void setOrderType(OrderType orderType) {
        this.orderType = orderType;
    }

    /** 获取关联业务ID **/
    public String getDataId() {
        return dataId;
    }

    /** 设置关联业务ID **/
    public void setDataId(String dataId) {
        this.dataId = dataId;
    }

    /** 获取订单内容(多个商品取总价最高的那个,加等几件) **/
    public String getOrderContent() {
        return orderContent;
    }

    /** 设置订单内容(多个商品取总价最高的那个,加等几件) **/
    public void setOrderContent(String orderContent) {
        this.orderContent = orderContent;
    }

    /** 获取用户ID **/
    public String getUserId() {
        return userId;
    }

    /** 设置用户ID **/
    public void setUserId(String userId) {
        this.userId = userId;
    }

    /** 获取总金额=商品金额-折扣+运费 **/
    public Double getTotalAmount() {
        return totalAmount;
    }

    /** 设置总金额=商品金额-折扣+运费 **/
    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = totalAmount;
    }

    /** 获取商品金额 **/
    public Double getGoodsAmount() {
        return goodsAmount;
    }

    /** 设置商品金额 **/
    public void setGoodsAmount(Double goodsAmount) {
        this.goodsAmount = goodsAmount;
    }

    /** 获取折扣金额 **/
    public Double getDiscountAmount() {
        return discountAmount;
    }

    /** 设置折扣金额 **/
    public void setDiscountAmount(Double discountAmount) {
        this.discountAmount = discountAmount;
    }

    /** 获取运费金额 **/
    public Double getFreightAmount() {
        return freightAmount;
    }

    /** 设置运费金额 **/
    public void setFreightAmount(Double freightAmount) {
        this.freightAmount = freightAmount;
    }

    /** 获取已支付金额 **/
    public Double getPaidAmount() {
        return paidAmount;
    }

    /** 设置已支付金额 **/
    public void setPaidAmount(Double paidAmount) {
        this.paidAmount = paidAmount;
    }

    /** 获取商品总件数 **/
    public Integer getTotalQuantity() {
        return totalQuantity;
    }

    /** 设置商品总件数 **/
    public void setTotalQuantity(Integer totalQuantity) {
        this.totalQuantity = totalQuantity;
    }

    /** 获取已发货件数 **/
    public Integer getDeliverQuantity() {
        return deliverQuantity;
    }

    /** 设置已发货件数 **/
    public void setDeliverQuantity(Integer deliverQuantity) {
        this.deliverQuantity = deliverQuantity;
    }

    /** 获取创建时间 **/
    public Date getCreateTime() {
        return createTime;
    }

    /** 设置创建时间 **/
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /** 获取过期时间 **/
    public Date getExpireTime() {
        return expireTime;
    }

    /** 设置过期时间 **/
    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    /** 获取订单状态(0.待支付|1.已支付|2.已交付|3.已完成|4.已取消|5.已过期) **/
    public OrderState getOrderState() {
        return orderState;
    }

    /** 设置订单状态(0.待支付|1.已支付|2.已交付|3.已完成|4.已取消|5.已过期) **/
    public void setOrderState(OrderState orderState) {
        this.orderState = orderState;
    }

    /** 获取选项 **/
    public OrderFormOptions getOptions() {
        return options;
    }

    /** 获取选项, force=是否强制返回非空对象 **/
    public OrderFormOptions getOptions(boolean force) {
        if (options == null && force) {
            options = new OrderFormOptions();
        }
        return options;
    }

    /** 设置选项 **/
    public void setOptions(OrderFormOptions options) {
        this.options = options;
    }

    /** 获取查询关键字 **/
    public String getQueryKeywords() {
        return queryKeywords;
    }

    /** 设置查询关键字 **/
    public void setQueryKeywords(String queryKeywords) {
        this.queryKeywords = queryKeywords;
    }

    /** 获取数据状态:0为正常|其他为删除 **/
    public DataState getDataState() {
        return dataState;
    }

    /** 设置数据状态:0为正常|其他为删除 **/
    public void setDataState(DataState dataState) {
        this.dataState = dataState;
    }

    /**
     * 将当前对象转换为子类对象
     *
     * @param clazz 目标类型
     * @return 目标对象
     */
    public <T extends OrderFormBean> T to(Class<T> clazz) {
        T instance;
        try {
            instance = clazz.newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to create " + clazz.getSimpleName() + " instance.", e);
        }

        instance.setId(this.getId()); // 主键
        instance.setTenantCode(this.getTenantCode()); // 商家租户编号
        instance.setOrderType(this.getOrderType()); // 订单类型(0.捐款订单|1.商品订单)
        instance.setDataId(this.getDataId()); // 关联业务ID
        instance.setOrderContent(this.getOrderContent()); // 订单内容(多个商品取总价最高的那个,加等几件)
        instance.setUserId(this.getUserId()); // 用户ID
        instance.setTotalAmount(this.getTotalAmount()); // 总金额=商品金额-折扣+运费
        instance.setGoodsAmount(this.getGoodsAmount()); // 商品金额
        instance.setDiscountAmount(this.getDiscountAmount()); // 折扣金额
        instance.setFreightAmount(this.getFreightAmount()); // 运费金额
        instance.setPaidAmount(this.getPaidAmount()); // 已支付金额
        instance.setTotalQuantity(this.getTotalQuantity()); // 商品总件数
        instance.setDeliverQuantity(this.getDeliverQuantity()); // 已发货件数
        instance.setCreateTime(this.getCreateTime()); // 创建时间
        instance.setExpireTime(this.getExpireTime()); // 过期时间
        instance.setOrderState(this.getOrderState()); // 订单状态(0.待支付|1.已支付|2.已交付|3.已完成|4.已取消|5.已过期)
        instance.setOptions(this.getOptions()); // 选项
        instance.setQueryKeywords(this.getQueryKeywords()); // 查询关键字
        instance.setDataState(this.getDataState()); // 数据状态:0为正常|其他为删除
        return instance;
    }

    /**
     * 将OrderFormBean转换为子类对象
     *
     * @param beans 待转换的对象列表
     * @param clazz 目标类型
     * @param <T> OrderFormBean或子类
     * @param <C> T的子类
     * @return 目标对象列表
     */
    public static <T extends OrderFormBean, C extends T> List<C> to(List<T> beans, Class<C> clazz) {
        if (beans == null) {
            return null;
        }
        List<C> list;
        if (beans instanceof PartList) {
            PartList<C> partlist = new PartList<>();
            partlist.setTotal(((PartList<?>) beans).getTotal());
            list = partlist;
        } else {
            list = new ArrayList<>();
        }
        for (OrderFormBean bean : beans) {
            list.add(bean.to(clazz));
        }
        return list;
    }

}